package cn.jetpiece.cloud.common.api.message;

import cn.jetpiece.cloud.common.api.message.model.params.CreateMessageConfigParam;
import cn.jetpiece.cloud.common.api.message.model.params.UpdateMessageConfigParam;
import cn.jetpiece.cloud.common.api.message.model.query.MessageConfigQuery;
import cn.jetpiece.cloud.common.api.message.model.result.MessageConfigResult;
import cn.jetpiece.cloud.model.page.PageResult;
import cn.jetpiece.cloud.model.response.Result;
import cn.jetpiece.cloud.resource.annotation.annotation.ApiResource;
import cn.jetpiece.cloud.resource.annotation.annotation.ScanResource;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.cloud.openfeign.SpringQueryMap;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import org.springframework.web.servlet.ModelAndView;

import javax.validation.Valid;
import java.util.Map;

/**
 * 消息配置
 *
 * @author jetpiece
 * @since 2022-11-22
 */
@Api(tags = "消息配置")
@ApiResource(name = "消息配置")
public interface MessageConfigApi {

    String API = "/common/message/messageConfigs";

    /**
     * 新增消息配置
     *
     * @param param 新增参数
     * @return 返回结果
     */
    @ApiOperation(value = "新增消息配置")
    @ScanResource(name = "新增消息配置", path = API, method = RequestMethod.POST)
    Result<String> add(@RequestBody @Valid CreateMessageConfigParam param);

    /**
     * 修改消息配置
     *
     * @param param 修改参数
     * @return 返回结果
     */
    @ApiOperation(value = "修改消息配置")
    @ScanResource(name = "修改消息配置", path = API, method = RequestMethod.PUT)
    Result<String> update(@RequestBody @Valid UpdateMessageConfigParam param);

    /**
     * 删除消息配置
     *
     * @param id 主键
     * @return 返回结果
     */
    @ApiOperation(value = "删除消息配置")
    @ScanResource(name = "删除消息配置", path = API + "/{id}", method = RequestMethod.DELETE)
    Result<String> delete(@PathVariable(name = "id") Long id);

    /**
     * 批量删除消息配置
     *
     * @param ids
     * @return 返回结果
     */
    @ApiOperation(value = "批量删除消息配置")
    @ScanResource(name = "批量删除消息配置", path = API + "/batch-del/{ids}", method = RequestMethod.DELETE)
    Result<String> deleteBatch(@PathVariable("ids") String ids);

    /**
     * 查询消息配置信息
     *
     * @param id 主键
     * @return 返回结果
     */
    @ApiOperation(value = "查询消息配置信息")
    @ScanResource(name = "查询消息配置信息", path = API + "/{id}", method = RequestMethod.GET)
    Result<MessageConfigResult> get(@PathVariable(name = "id") Long id);

    /**
     * 分页获取消息配置
     *
     * @param query 查询条件
     * @return 返回结果
     */
    @ApiOperation(value = "分页获取消息配置")
    @ScanResource(name = "分页获取消息配置", path = API, method = RequestMethod.GET)
    Result<PageResult<MessageConfigResult>> page(@Valid @SpringQueryMap MessageConfigQuery query);

    /**
     * 通过Excel导入消息配置数据
     *
     * @return 返回结果
     */
    @ApiOperation(value = "通过Excel导入消息配置数据")
    @ScanResource(name = "通过Excel导入消息配置数据", path = API + "/import-excel", method = RequestMethod.POST)
    Result<String> importExcel(MultipartHttpServletRequest request);

    /**
     * 导出消息配置数据到Excel
     *
     * @param query 查询条件
     * @return 返回结果
     */
    @ApiOperation(value = "通过excel导入消息配置数据")
    @ScanResource(name = "通过excel导入消息配置数据", path = API + "/export-excel", method = RequestMethod.GET)
    ModelAndView exportExcel(@Valid @SpringQueryMap MessageConfigQuery query);

    /**
     * 获取通知类型
     *
     * @return 返回结果
     */
    @ApiOperation(value = "获取通知类型")
    @ScanResource(name = "获取通知类型", path = API + "/notify-types", method = RequestMethod.GET)
    Result<PageResult<Map<String, Object>>> notifyTypes();

    /**
     * 获取通知配置
     *
     * @param notifyType 通知类型
     * @return 返回结果
     */
    @ApiOperation(value = "获取通知配置")
    @ScanResource(name = "获取通知配置", path = API + "/notify-configs", method = RequestMethod.GET)
    Result<PageResult<Map<String, Object>>> notifyConfigPage(@RequestParam(value = "notifyType", required = false) String notifyType);

    /**
     * 分页获取通知模板
     *
     * @param notifyType 通知类型
     * @return 返回结果
     */
    @ApiOperation(value = "分页获取通知模板")
    @ScanResource(name = "分页获取通知模板", path = API + "/notify-templates", method = RequestMethod.GET)
    Result<PageResult<Map<String, Object>>> notifyTemplatePage(@RequestParam(value = "notifyType", required = false) String notifyType);

    /**
     * 获取通知模板
     *
     * @param templateId 模板ID
     * @return 返回结果
     */
    @ApiOperation(value = "获取通知模板")
    @ScanResource(name = "获取通知模板", path = API + "/notify-templates/{templateId}", method = RequestMethod.GET)
    Result<Map<String, Object>> template(@PathVariable(name = "templateId") String templateId);

    /**
     * 发送消息
     *
     * @param id 主键
     * @return 返回结果
     */
    @ApiOperation(value = "发送消息")
    @ScanResource(name = "发送消息", path = API + "/{id}/send", method = RequestMethod.POST)
    Result<Object> sendById(@PathVariable(name = "id") Long id, @RequestBody Map<String, Object> params);

    /**
     * 发送消息
     *
     * @param notifyConfigId 通知配置ID
     * @param templateId     发送消息 模板ID
     * @param params         消息参数
     * @return 返回结果
     */
    @ApiOperation(value = "发送消息")
    @ScanResource(name = "发送消息", path = API + "/send/{notifyConfigId}/{templateId}", method = RequestMethod.POST)
    Result<Object> send(@PathVariable(name = "notifyConfigId") String notifyConfigId, @PathVariable(name = "templateId") String templateId, @RequestBody Map<String, Object> params);
}
